import { Connector } from "cax-connector"
import { Application } from "../application"

export function initEventListener(connector: Connector, app: Application) {
    connector.client.on("viewport", (buffer) => {
        const blob = new Blob([buffer], { type: "image/jpeg" })
        const url = URL.createObjectURL(blob)
        app.draw(url)
    })
    connector.client.on("connect", () => {
        console.log("连接成功")
        app.view.update()
    })
    connector.client.on("disconnect", () => {
        console.log("连接断开")
    })
    connector.client.on("reconnect", (err) => {
        app.view.update()
        console.log("重新连接")
    })
}
